package org.javaboy.vhr.controller.personnel;

import org.javaboy.vhr.model.Employeeec;
import org.javaboy.vhr.model.RespBean;
import org.javaboy.vhr.model.RespPageBean;
import org.javaboy.vhr.service.EmployeeecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/personnel/ec")
public class EmpEcController {
    @Autowired
    EmployeeecService employeeecService;

    /**
     * 用到
     * 获取所有员工奖惩记录（分页）
     * @param page 页码
     * @param size 每页大小
     * @param keyword 关键词搜索
     * @return 奖惩记录列表
     */
    @GetMapping("/")
    public RespPageBean getAllEmpec(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer size,
                                  String keyword) {
        return employeeecService.getAllEmpec(page, size, keyword);
    }



    /**
     *用到
     * 增加奖惩记录
     * @param employeeec 奖惩记录对象
     * @return 添加结果
     */
    @PostMapping("/")
    public RespBean addEmpec(@RequestBody Employeeec employeeec) {
        if (employeeecService.addEmpec(employeeec) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    /**
     * 用到
     * 更新奖惩记录
     * @param employeeec 奖惩记录对象
     * @return 更新结果
     */
    @PutMapping("/")
    public RespBean updateEmpec(@RequestBody Employeeec employeeec) {
        if (employeeecService.updateEmpec(employeeec) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }
    /**
     * 删除奖惩记录
     * @param id 记录ID
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    public RespBean deleteEmpec(@PathVariable Integer id) {
        if (employeeecService.deleteEmpec(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    /**
     * 批量删除奖惩记录
     * @param ids 记录ID数组
     * @return 删除结果
     */
    @DeleteMapping("/")
    public RespBean deleteEmpecByIds(Integer[] ids) {
        if (employeeecService.deleteEmpecByIds(ids) == ids.length) {
            return RespBean.ok("批量删除成功!");
        }
        return RespBean.error("批量删除失败!");
    }

    /**
     * 未用到
     * 获取指定员工的奖惩记录
     * @param eid 员工ID
     * @return 奖惩记录列表
     */
    @GetMapping("/emp/{eid}")
    public List<Employeeec> getEmpecByEid(@PathVariable Integer eid) {
        return employeeecService.getEmpecByEid(eid);
    }
    /**
     * 未用到
     * 获取单个奖惩记录
     * @param id 记录ID
     * @return 奖惩记录对象
     */
    @GetMapping("/{id}")
    public Employeeec getEmpecById(@PathVariable Integer id) {
        return employeeecService.getEmpecById(id);
    }
}
